package com.zhuzg.service.impl;


import com.zhuzg.domain.Order;
import com.zhuzg.feign.AccountService;
import com.zhuzg.feign.StoreService;
import com.zhuzg.mapper.OrderMapper;
import com.zhuzg.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

//
@Service

public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    StoreService storeService;

    @Autowired
    AccountService accountService;

    @Override
    @GlobalTransactional
    public int createOrder(Order order) {

        storeService.deduce(order.getGoodsId(),order.getBuyNum());
        accountService.deduce(order.getUserId(),order.getUnitPrice().multiply( new BigDecimal(order.getBuyNum())));

        return orderMapper.insert(order);

    }
}
